
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Bean工具类 · Diboot基础框架</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-theme-vuejs-2/vue.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="JSON.html" />
    
    
    <link rel="prev" href="V.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                



<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../开始使用.html">
            
                <a href="../开始使用.html">
            
                    
                    开始使用
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../开始使用/搭建环境.html">
            
                <a href="../开始使用/搭建环境.html">
            
                    
                    搭建环境
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../开始使用/使用framework.html">
            
                <a href="../开始使用/使用framework.html">
            
                    
                    使用diboot-framework
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../CRUD通用封装.html">
            
                <a href="../CRUD通用封装.html">
            
                    
                    CRUD通用封装
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../CRUD通用封装/Model基类.html">
            
                <a href="../CRUD通用封装/Model基类.html">
            
                    
                    Model基类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../CRUD通用封装/Service基类.html">
            
                <a href="../CRUD通用封装/Service基类.html">
            
                    
                    Service基类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../CRUD通用封装/Mapper基类与SQL.html">
            
                <a href="../CRUD通用封装/Mapper基类与SQL.html">
            
                    
                    Mapper基类与SQL
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../MVC通用封装.html">
            
                <a href="../MVC通用封装.html">
            
                    
                    MVC通用封装
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../MVC通用封装/Controller基类.html">
            
                <a href="../MVC通用封装/Controller基类.html">
            
                    
                    Controller基类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../MVC通用封装/CrudController基类.html">
            
                <a href="../MVC通用封装/CrudController基类.html">
            
                    
                    CrudController基类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../MVC通用封装/CrudRestController基类.html">
            
                <a href="../MVC通用封装/CrudRestController基类.html">
            
                    
                    CrudRestController基类
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../认证与安全.html">
            
                <a href="../认证与安全.html">
            
                    
                    认证与安全
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../认证与安全/jwt授权.html">
            
                <a href="../认证与安全/jwt授权.html">
            
                    
                    JWT认证
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../认证与安全/CSRF防护.html">
            
                <a href="../认证与安全/CSRF防护.html">
            
                    
                    CSRF防护
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../认证与安全/XSS防护.html">
            
                <a href="../认证与安全/XSS防护.html">
            
                    
                    XSS防护
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../系统参数配置.html">
            
                <a href="../系统参数配置.html">
            
                    
                    系统参数配置
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../系统参数配置/配置文件.html">
            
                <a href="../系统参数配置/配置文件.html">
            
                    
                    参数配置在文件中
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../系统参数配置/数据库表.html">
            
                <a href="../系统参数配置/数据库表.html">
            
                    
                    参数配置在数据库表中
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../系统日志记录.html">
            
                <a href="../系统日志记录.html">
            
                    
                    系统日志记录
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../系统日志记录/操作日志.html">
            
                <a href="../系统日志记录/操作日志.html">
            
                    
                    操作日志
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../系统日志记录/跟踪日志.html">
            
                <a href="../系统日志记录/跟踪日志.html">
            
                    
                    跟踪日志
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../常用工具类.html">
            
                <a href="../常用工具类.html">
            
                    
                    常用工具类
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="D.html">
            
                <a href="D.html">
            
                    
                    日期时间类D
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="S.html">
            
                <a href="S.html">
            
                    
                    字符串类S
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="V.html">
            
                <a href="V.html">
            
                    
                    数据校验类V
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.8.4" data-path="BeanUtils.html">
            
                <a href="BeanUtils.html">
            
                    
                    Bean工具类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.5" data-path="JSON.html">
            
                <a href="JSON.html">
            
                    
                    Json工具类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.6" data-path="Encryptor.html">
            
                <a href="Encryptor.html">
            
                    
                    加解密类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.7" data-path="IdGenerator.html">
            
                <a href="IdGenerator.html">
            
                    
                    ID生成器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.8" data-path="Query.html">
            
                <a href="Query.html">
            
                    
                    条件构造器
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../通用基础模型.html">
            
                <a href="../通用基础模型.html">
            
                    
                    通用基础模型
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="../通用基础模型/用户角色权限.html">
            
                <a href="../通用基础模型/用户角色权限.html">
            
                    
                    用户角色权限
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.2" data-path="../通用基础模型/元数据.html">
            
                <a href="../通用基础模型/元数据.html">
            
                    
                    元数据
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.3" data-path="../通用基础模型/文件.html">
            
                <a href="../通用基础模型/文件.html">
            
                    
                    文件
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>



                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                

                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >Bean工具类</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i><ul><li><span class="title-icon "></span><a href="#bean&#x5DE5;&#x5177;&#x7C7B;"><b>1. </b>Bean&#x5DE5;&#x5177;&#x7C7B;</a></li></ul></div><a href="#bean&#x5DE5;&#x5177;&#x7C7B;" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a><h1 id="bean&#x5DE5;&#x5177;&#x7C7B;"><a name="bean&#x5DE5;&#x5177;&#x7C7B;" class="anchor-navigation-ex-anchor" href="#bean&#x5DE5;&#x5177;&#x7C7B;"><i class="fa fa-link" aria-hidden="true"></i></a>1. Bean&#x5DE5;&#x5177;&#x7C7B;</h1>
<blockquote>
<p>Bean&#x5DE5;&#x5177;&#x7C7B;&#x53EF;&#x4EE5;&#x8FDB;&#x884C;&#x4E0E;&#x6A21;&#x578B;&#x76F8;&#x5173;&#x7684;&#x5904;&#x7406;&#xFF0C;&#x901A;&#x8FC7;&#x7C7B;&#x4F3C;BeanUtils.copyProperties()&#x8FD9;&#x6837;&#x7684;&#x8C03;&#x7528;&#x5373;&#x53EF;&#x4F7F;&#x7528;&#x76F8;&#x5173;&#x65B9;&#x6CD5;&#x3002;</p>
</blockquote>
<ul>
<li><p>&#x4EC5;&#x4F9D;&#x8D56;Spring&#x7684;BeanUtils&#x7C7B;&#xFF08;&#x4E0D;&#x9700;&#x4F9D;&#x8D56;apache&#x7684;BeanUtils&#xFF09;</p>
</li>
<li><p>&#x62F7;&#x8D1D;&#x5C5E;&#x6027;</p>
</li>
</ul>
<pre><code class="lang-java"><span class="hljs-function">Object <span class="hljs-title">copyProperties</span><span class="hljs-params">(Object source, Object target)</span></span>;
</code></pre>
<ul>
<li>&#x7ED1;&#x5B9A;map&#x4E2D;&#x7684;&#x5C5E;&#x6027;&#x5230;model</li>
</ul>
<pre><code class="lang-java"><span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">bindProperties</span><span class="hljs-params">(BaseModel model, Map&lt;String, Object&gt; propMap)</span></span>;
</code></pre>
<ul>
<li>&#x5C06;request&#x8BF7;&#x6C42;&#x53C2;&#x6570;&#x503C;&#x7ED1;&#x5B9A;&#x5230;model</li>
</ul>
<pre><code class="lang-java"><span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">buildModel</span><span class="hljs-params">(BaseModel model, HttpServletRequest request)</span></span>;
</code></pre>
<ul>
<li>&#x5C06;model&#x5217;&#x8868;&#x8F6C;&#x6362;&#x4E3A;&lt;&#x6307;&#x5B9A;&#x5B57;&#x6BB5;&#x503C;-model&gt;&#x7684;map&#x5BF9;&#x8C61;&#xFF0C;&#x7528;&#x4E8E;&#x540E;&#x7EED;&#x5FEB;&#x901F;&#x6839;&#x636E;&#x6307;&#x5B9A;&#x5B57;&#x6BB5;&#x503C;&#x67E5;&#x627E;&#x5230;&#x5BF9;&#x5E94;&#x7684;model&#x5BF9;&#x8C61;</li>
</ul>
<pre><code class="lang-java">&lt;T extends BaseModel&gt; <span class="hljs-function">Map&lt;Object, T&gt; <span class="hljs-title">convert2KeyModelMap</span><span class="hljs-params">(List&lt;T&gt; allLists, String... fields)</span></span>;
</code></pre>
<ul>
<li>&#x5C06;model&#x5217;&#x8868;&#x8F6C;&#x6362;&#x4E3A;&lt;&#x6307;&#x5B9A;&#x5B57;&#x6BB5;&#x503C;-model&#x5217;&#x8868;&gt;&#x7684;map&#x5BF9;&#x8C61;&#xFF0C;&#x7528;&#x4E8E;&#x540E;&#x7EED;&#x5FEB;&#x901F;&#x6839;&#x636E;&#x6307;&#x5B9A;&#x5B57;&#x6BB5;&#x503C;&#x67E5;&#x627E;&#x5230;&#x5BF9;&#x5E94;&#x7684;model&#x5217;&#x8868;</li>
</ul>
<pre><code class="lang-java">&lt;T extends BaseModel&gt; Map&lt;Object, List&lt;T&gt;&gt; convert2KeyModelListMap(List&lt;T&gt; allLists, String field);
</code></pre>
<ul>
<li>&#x5C06;treeModel&#x5217;&#x8868;&#x8F6C;&#x6362;&#x4E3A;&#x6811;&#x5F62;&#x7ED3;&#x6784;&#x7684;&#x5BF9;&#x8C61;&#x5217;&#x8868;&#xFF08;&#x8FD4;&#x56DE;&#x9876;&#x5C42;&#x5BF9;&#x8C61;&#x5217;&#x8868;&#xFF0C;&#x5B50;&#x7EA7;&#x8282;&#x70B9;&#x6302;&#x8F7D;&#x5230;&#x7236;&#x7EA7;&#x7684;children&#x5BF9;&#x8C61;&#x4E2D;&#xFF09;</li>
</ul>
<pre><code class="lang-java">&lt;T extends BaseTreeModel&gt; <span class="hljs-function">List&lt;T&gt; <span class="hljs-title">buildTreeModels</span><span class="hljs-params">(List&lt;T&gt; allModels)</span></span>;
</code></pre>
<ul>
<li>&#x63D0;&#x53D6;&#x4E24;&#x4E2A;model&#x5BF9;&#x8C61;&#x7684;&#x5DEE;&#x5F02;(&#x7528;&#x4E8E;&#x8DDF;&#x8E2A;&#x65E5;&#x5FD7;&#x8BB0;&#x5F55;&#x6570;&#x636E;&#x53D8;&#x5316;)</li>
</ul>
<pre><code class="lang-java"><span class="hljs-function">String <span class="hljs-title">extractDiff</span><span class="hljs-params">(BaseModel oldModel, BaseModel newModel)</span></span>;
</code></pre>
<ul>
<li>&#x7ED1;&#x5B9A;&#x4E00;&#x5BF9;&#x4E00;&#x7684;&#x5173;&#x7CFB;&#xFF08;&#x6839;&#x636E;&#x6307;&#x5B9A;&#x7684;&#x5C5E;&#x6027;&#x503C;&#x76F8;&#x7B49;&#x81EA;&#x52A8;&#x7ED1;&#x5B9A;&#x4E00;&#x5BF9;&#x4E00;&#x7684;&#x5173;&#x7CFB;&#xFF09;</li>
</ul>
<pre><code class="lang-java"><span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">bindOne2One</span><span class="hljs-params">(List&lt;? extends BaseModel&gt; leftModelList, String leftModelBindField, List&lt;? extends BaseModel&gt; rightModelList, String left2rightMapping)</span></span>;

<span class="hljs-comment">// &#x793A;&#x4F8B;&#x5982;&#x4E0B;&#xFF1A;</span>
BeanUtils.bindOne2One(users, <span class="hljs-string">&quot;department&quot;</span>, departments, <span class="hljs-string">&quot;id=id&quot;</span>);
</code></pre>
<ul>
<li>&#x7ED1;&#x5B9A;&#x4E00;&#x5BF9;&#x591A;&#x7684;&#x5173;&#x7CFB;&#xFF08;&#x6839;&#x636E;&#x6307;&#x5B9A;&#x7684;&#x5C5E;&#x6027;&#x503C;&#x76F8;&#x7B49;&#x81EA;&#x52A8;&#x7ED1;&#x5B9A;&#x4E00;&#x5BF9;&#x591A;&#x7684;&#x5173;&#x7CFB;&#xFF09;</li>
</ul>
<pre><code class="lang-java"><span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">bindOne2Many</span><span class="hljs-params">(BaseModel model, String oneModelField, List&lt;? extends BaseModel&gt; manyModelList, String left2rightMapping)</span>&#xFF1B;

<span class="hljs-comment">// &#x793A;&#x4F8B;&#x5982;&#x4E0B;&#xFF1A;</span>
BeanUtils.<span class="hljs-title">bindOne2Many</span><span class="hljs-params">(users, <span class="hljs-string">&quot;menus&quot;</span>, menus, <span class="hljs-string">&quot;id=id&quot;</span>)</span></span>;
</code></pre>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                

            </div>

            
                
                <a href="V.html" class="navigation navigation-prev " aria-label="Previous page: 数据校验类V">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="JSON.html" class="navigation navigation-next " aria-label="Next page: Json工具类">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"Bean工具类","level":"1.8.4","depth":2,"next":{"title":"Json工具类","level":"1.8.5","depth":2,"path":"常用工具类/JSON.md","ref":"常用工具类/JSON.md","articles":[]},"previous":{"title":"数据校验类V","level":"1.8.3","depth":2,"path":"常用工具类/V.md","ref":"常用工具类/V.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-sharing","sharing-plus","anchor-navigation-ex","theme-vuejs-2"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"search":{},"sharing-plus":{"qq":false,"all":["facebook","google","twitter","instapaper","linkedin","pocket","stumbleupon"],"douban":false,"facebook":true,"weibo":false,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":true,"messenger":false,"line":false,"vk":false,"pocket":true,"google":false,"viber":false,"stumbleupon":false,"qzone":false,"linkedin":false},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"theme-vuejs-2":{},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"anchor-navigation-ex":{"mode":"float","pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"showLevel":true,"tocLevel1Icon":"fa fa-hand-o-right","tocLevel2Icon":"fa fa-hand-o-right","tocLevel3Icon":"fa fa-hand-o-right","showGoTop":true,"isShowTocTitleIcon":true,"printLog":false,"multipleH1":true,"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false}},"sharing":{"qq":true,"all":["weibo","qq","linkedin","qzone","douban"],"douban":false,"weibo":true,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":false,"messenger":false,"line":false,"vk":false,"pocket":false,"viber":false,"stumbleupon":false,"qzone":true,"linkedin":false},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Diboot基础框架","gitbook":"*","description":"Diboot基础框架"},"file":{"path":"常用工具类/BeanUtils.md","mtime":"2018-11-08T08:51:40.504Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-11-10T15:08:25.671Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-sharing-plus/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

